﻿///#undef MySql
///#define MSSql
#define MySql

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///using System.Data.SqlClient;
using System.Text.RegularExpressions;

///using MySql.Data.MySqlClient;


namespace ukeasbjWeb
{
    public partial class RegisterEdit : Bonus
    {
        //合同主键
        string sSeries_No;

        protected void Page_Load(object sender, EventArgs e)
        {     
        
            // 操作权限的判断
            Common_SXD.Is_LongIn(Response, Session, Request);

            bool bIs_Admin = Convert.ToBoolean(Session["Is_Admin"]);
            bool bIs_O_M = Convert.ToBoolean(Session["Is_O_M"]);
            bool bIs_Marketing = Convert.ToBoolean(Session["Is_Marketing"]);

            bool bIs_Receptionist = Convert.ToBoolean(Session["Is_Receptionist"]);
            bool bIs_Counsellor = Convert.ToBoolean(Session["Is_Counsellor"]);
            bool bIs_Frontline_Agent = Convert.ToBoolean(Session["Is_Frontline_Agent"]);
            string Name_Email = Session["Email"].ToString().Trim().ToLower();

            if (!bIs_O_M && !bIs_Admin && !bIs_Counsellor )
            { //只有地区经理、系统管理员、顾问可以进入
                Response.Write("<h2 align='center'><font face='宋体' color='red'>");
                Response.Write("<br>对不起，请用其他身份登录！");
                Response.Write("</fong></h2>");
                Response.End();
            }

            ///////////// 读出合同主键
            sSeries_No = Request["Series_No"];
            Session["Flag"] = sSeries_No;
            ///////////// 分离加在合同主键前部的控制字符
            Regex NotEditFirstPayment = new Regex("([a-zA-Z_]{1,}):([0-9]{1,})");
            Regex NewOneFirstPayment = new Regex("(NewOne)");
            Regex EditFirstPayment = new Regex("([0-9]{1,})");
            string[] temp;

            if (!IsPostBack)
            {
             
                // 长期课程院校1
                Common_SXD.Init_DropDownList(Drop_College1_Degree_courses, "School",
                    ///"select * from Schools1 order by School asc");
                    "select * from Schools_HTS where Is_College1_Degree_courses = 1 order by School asc");

                //  长期课程院校2
                Common_SXD.Init_DropDownList(Drop_College2_Degree_courses, "School",
                    ///"select * from Schools2 order by School asc");
                    "select * from Schools_HTS where Is_College2_Degree_courses = 1 order by School asc");
                //  学前语言学校
                Common_SXD.Init_DropDownList(Drop_College_Pre_sessional, "School",
                    ///"select * from Schools1 order by School asc");
                    "select * from Schools_HTS where Is_College1_Degree_courses = 1 order by School asc");

                //  语言学校
                Common_SXD.Init_DropDownList(Drop_College_Language_School, "School",
                    ///"select * from Language_Schools order by School asc");
                    "select * from Schools_HTS where Is_College_Language_School = 1 order by School asc");
                Common_SXD.Init_YearMonth_Start(Drop_YearMonth_Start);

                ///学前语言Type
                Common_SXD.Init_DropDownList(Drop_Type_Pre_sessional, "Type_Register",
                    "select * from Type_Register order by Code_Type_Register asc");

                ///长期课程1 Type
                Common_SXD.Init_DropDownList(Drop_Type1_Degree_courses, "Type_Register",
                    "select * from Type_Register order by Code_Type_Register asc");

                ///长期课程2 Type
                Common_SXD.Init_DropDownList(Drop_Type2_Degree_courses, "Type_Register",
                    "select * from Type_Register order by Code_Type_Register asc");
                
            }

            if (NotEditFirstPayment.IsMatch(sSeries_No))
            {
                temp = NotEditFirstPayment.Split(sSeries_No);
                if (temp[1] == "ReadOnly")
                {// 只读方式读取合同数据
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                        //Init_ReadOnly();
                    Label_Msg.Text = sSeries_No;
                    return;
                }
                else if (temp[1] == "EditRegisterData")
                {// 
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                    {
                        Init_EditRegisterData();
                        Init_EditCommissionData();
                    }
                    Label_Msg.Text = sSeries_No;
                    return;
                }
                else if (temp[1] == "AddedRegisterData")
                {
                    sSeries_No = temp[2];
                    if (!IsPostBack)
                        Init_AddedRegisterData();
                    Label_Msg.Text = sSeries_No;
                    return;

                }
                

            }
            
            
        }


        /// <summary>
        /// 初始化： 添加注册数据
        /// </summary>
        private void Init_AddedRegisterData()
        {
            Init_EditRegisterData();
            Init_EditCommissionData();
        }

        /// <summary>
        /// 初始化：修改注册数据
        /// </summary>
        private void Init_EditRegisterData()
        {
            Admin_Accountant_Controls();
            false_Enable_Some_Controls();


            // 根据传入的合同编号，生成查询 SQL 语句
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
#if MSSql
            DataSet bsDataSet = Common_SXD.Init_MSSql_DataSet("Contract", sSql);
#elif MySql
            DataSet bsDataSet = Common_SXD.Init_MySql_DataSet("Contract", sSql);
#endif
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行

                //////////////////////////
                // 学生基本信息
                TextBox_Office.Text = rowUser["Office"].ToString().Trim();


                TextBox_Counsellor.Text = rowUser["Counsellor"].ToString().Trim();
                TextBox_UKEAS_ID.Text = rowUser["UKEAS_ID"].ToString().Trim();
                TextBox_YearMonth_Start.Text = rowUser["YearMonth_Start"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["YearMonth_Start"].ToString().Trim(), Drop_YearMonth_Start);
                TextBox_Student_Name.Text = rowUser["Student_Name"].ToString().Trim();
                TextBox_Date_Birth.Text = rowUser["Date_Birth"].ToString().Trim();
                TextBox_Date_Birth.Text = Common_SXD.TimeToYMD(TextBox_Date_Birth.Text);
                Common_SXD.SetSelectedIndex(rowUser["Gender_Student"].ToString().Trim(), Drop_Gender_Student);

                TextBox_Pinyi.Text = rowUser["Pinyi"].ToString().Trim();

                //////////////////////////////////
                ////////长期课程院校1
                Common_SXD.SetSelectedIndex(rowUser["College1_Degree_courses"].ToString().Trim(), Drop_College1_Degree_courses);

                // 长期课程选择菜单初始化
                string temp;
                temp = "select * from Courses_Schools where Course like '无' or School like '" + Double_Single_Quotation(Drop_College1_Degree_courses.SelectedItem.Text.Trim()) + "' order by Course asc";
                Common_SXD.Init_DropDownList(Drop_Course1_Degree_courses, "Course", temp);

                TextBox_Course1_Degree_courses.Text = rowUser["Course1_Degree_courses"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Course1_Degree_courses"].ToString().Trim(), Drop_Course1_Degree_courses);

                TextBox_Start1_Degree_courses.Text = rowUser["Start1_Degree_courses"].ToString().Trim();
                TextBox_Start1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Start1_Degree_courses.Text);
                TextBox_Finish1_Degree_courses.Text = rowUser["Finish1_Degree_courses"].ToString().Trim();
                TextBox_Finish1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Finish1_Degree_courses.Text);

                Common_SXD.SetSelectedIndex(rowUser["Level1_Degree_courses"].ToString().Trim(), Drop_Level1_Degree_courses);
                Common_SXD.SetSelectedIndex(rowUser["Type1_Degree_courses"].ToString().Trim(), Drop_Type1_Degree_courses);
                TextBox_Tuition1_Degree_courses.Text = rowUser["Tuition1_Degree_courses"].ToString().Trim();
                TextBox_Ref_No1_Degree_courses.Text = rowUser["Ref_No1_Degree_courses"].ToString().Trim();
                ///From_Same_School
                ///
                temp = rowUser["Helicopter1_Degree_courses"].ToString().Trim();
                if ((rowUser["Helicopter1_Degree_courses"].ToString().Trim() == "True") ||
                    (rowUser["Helicopter1_Degree_courses"].ToString().Trim() == "1"))
                    CheckBox_Helicopter1_Degree_courses.Checked = true;
                else
                    CheckBox_Helicopter1_Degree_courses.Checked = false;

                TextBox_Notes1_Degree_courses.Text = rowUser["Notes1_Degree_courses"].ToString().Trim();


                //////////////////////////////////
                ////////长期课程院校2
                Common_SXD.SetSelectedIndex(rowUser["College2_Degree_courses"].ToString().Trim(), Drop_College2_Degree_courses);
                // 长期课程2
                TextBox_Course2_Degree_courses.Text = rowUser["Course2_Degree_courses"].ToString().Trim();

                TextBox_Start2_Degree_courses.Text = rowUser["Start2_Degree_courses"].ToString().Trim();
                TextBox_Start2_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Start2_Degree_courses.Text);
                TextBox_Finish2_Degree_courses.Text = rowUser["Finish2_Degree_courses"].ToString().Trim();
                TextBox_Finish2_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Finish2_Degree_courses.Text);

                Common_SXD.SetSelectedIndex(rowUser["Level2_Degree_courses"].ToString().Trim(), Drop_Level2_Degree_courses);
                Common_SXD.SetSelectedIndex(rowUser["Type2_Degree_courses"].ToString().Trim(), Drop_Type2_Degree_courses);
                TextBox_Tuition2_Degree_courses.Text = rowUser["Tuition2_Degree_courses"].ToString().Trim();
                TextBox_Ref_No2_Degree_courses.Text = rowUser["Ref_No2_Degree_courses"].ToString().Trim();
                ///From_Same_School
                if (rowUser["Helicopter2_Degree_courses"].ToString().Trim() == "1")
                    CheckBox_Helicopter2_Degree_courses.Checked = true;
                else
                    CheckBox_Helicopter2_Degree_courses.Checked = false;

                TextBox_Notes2_Degree_courses.Text = rowUser["Notes2_Degree_courses"].ToString().Trim();

                ///学前语言院校
                ///
                Common_SXD.SetSelectedIndex(rowUser["College_Pre_sessional"].ToString().Trim(), Drop_College_Pre_sessional);
                TextBox_Course_Pre_sessional.Text = rowUser["Course_Pre_sessional"].ToString().Trim();

                TextBox_Wks_Pre_sessional.Text = rowUser["Wks_Pre_sessional"].ToString().Trim();
                Common_SXD.SetSelectedIndex(rowUser["Type_Pre_sessional"].ToString().Trim(), Drop_Type_Pre_sessional);
                TextBox_Start_Pre_sessional.Text = rowUser["Start_Pre_sessional"].ToString().Trim();
                TextBox_Start_Pre_sessional.Text = Common_SXD.TimeToYMD(TextBox_Start_Pre_sessional.Text);
                TextBox_Finish_Pre_sessional.Text = rowUser["Finish_Pre_sessional"].ToString().Trim();
                TextBox_Finish_Pre_sessional.Text = Common_SXD.TimeToYMD(TextBox_Finish_Pre_sessional.Text);

                TextBox_Fee_Pre_sessional.Text = rowUser["Fee_Pre_sessional"].ToString().Trim();
                TextBox_Ref_No_Pre_sessional.Text = rowUser["Ref_No_Pre_sessional"].ToString().Trim();
                ///From_Same_School
                TextBox_Notes_Pre_sessional.Text = rowUser["Notes_Pre_sessional"].ToString().Trim();


                ////语言院校
                Common_SXD.SetSelectedIndex(rowUser["College_Language_School"].ToString().Trim(), Drop_College_Language_School);
                TextBox_Course_Language_School.Text = rowUser["Course_Language_School"].ToString().Trim();

                TextBox_Wks_Language_School.Text = rowUser["Wks_Language_School"].ToString().Trim();
                TextBox_Start_Language_School.Text = rowUser["Start_Language_School"].ToString().Trim();
                TextBox_Start_Language_School.Text = Common_SXD.TimeToYMD(TextBox_Start_Language_School.Text);
                TextBox_Finish_Language_School.Text = rowUser["Finish_Language_School"].ToString().Trim();
                TextBox_Finish_Language_School.Text = Common_SXD.TimeToYMD(TextBox_Finish_Language_School.Text);

                //Common_SXD.SetSelectedIndex(rowUser["Type_Pre_sessional"].ToString().Trim(), Drop_Type_Pre_sessional);
                TextBox_Fee_Language_School.Text = rowUser["Fee_Language_School"].ToString().Trim();
                //TextBox_Ref_No1_Degree_courses.Text = rowUser["Ref_No2_Degree_courses"].ToString().Trim();
                ///From_Same_School
                TextBox_Notes_Language_School.Text = rowUser["Notes_Language_School"].ToString().Trim();

                ///校外住宿
                ///
                Common_SXD.SetSelectedIndex(rowUser["Private_Co_accommodation_name"].ToString().Trim(), Drop_Private_Co_accommodation_name);
                TextBox_Residence_Name_Co_accommodation.Text = rowUser["Residence_Name_Co_accommodation"].ToString().Trim();

                TextBox_Wks_Co_accommodation.Text = rowUser["Wks_Co_accommodation"].ToString().Trim();
                TextBox_Start_Co_accommodation.Text = rowUser["Start_Co_accommodation"].ToString().Trim();
                TextBox_Start_Co_accommodation.Text = Common_SXD.TimeToYMD(TextBox_Start_Co_accommodation.Text);
                TextBox_Finish_Co_accommodation.Text = rowUser["Finish_Co_accommodation"].ToString().Trim();
                TextBox_Finish_Co_accommodation.Text = Common_SXD.TimeToYMD(TextBox_Finish_Co_accommodation.Text);

                //Common_SXD.SetSelectedIndex(rowUser["Type_Pre_sessional"].ToString().Trim(), Drop_Type_Pre_sessional);
                TextBox_Fee_Co_accommodation.Text = rowUser["Fee_Co_accommodation"].ToString().Trim();
                TextBox_Ref_No_Co_accommodation.Text = rowUser["Ref_No_Co_accommodation"].ToString().Trim();

                TextBox_Notes_Co_accommodation.Text = rowUser["Notes_Co_accommodation"].ToString().Trim();

                ///INTO保险金额
                ///
                TextBox_Fee_INTO_Insurance.Text = rowUser["Fee_INTO_Insurance"].ToString().Trim();
            }
        }
        /// <summary>
        /// 初始化：修改佣金数据
        /// </summary>
        private void Init_EditCommissionData()
        {
            Admin_Accountant_Controls();
            Commission_Controls();
            ////
            /*if (!CheckBox_Commission_1_Degree_courses.Checked)
            {
                Response.Write("<li>不能修改佣金数据！</li>");
                return;
            }
            */

            // 根据传入的合同编号，生成查询 SQL 语句
            string sSql = "select * from contract where Series_No = " + "'" + sSeries_No + "'";
#if MSSql
            DataSet bsDataSet = Common_SXD.Init_MSSql_DataSet("Contract", sSql);
#elif MySql
            DataSet bsDataSet = Common_SXD.Init_MySql_DataSet("Contract", sSql);
#endif
            if (bsDataSet.Tables["Contract"].Rows.Count == 1)
            {
                DataRow rowUser = bsDataSet.Tables["Contract"].Rows[0]; // 只有一行
                
                //////////////////////////
                /// 课程1佣金比例
                TextBox_Rate_1_Degree_courses.Text = rowUser["Rate_1_Degree_courses"].ToString().Trim();
                
                // 课程1佣金收到日期，发票编号，发票日期，金额，注释
                TextBox_Received_Date1_1_Degree_courses.Text = rowUser["Received_Date1_1_Degree_courses"].ToString().Trim();
                TextBox_Received_Date1_1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Received_Date1_1_Degree_courses.Text);
                
                TextBox_Invoice_No1_1_Degree_courses.Text = rowUser["Invoice_No1_1_Degree_courses"].ToString().Trim();
                TextBox_Invoice_Date1_1_Degree_courses.Text = rowUser["Invoice_Date1_1_Degree_courses"].ToString().Trim();
                TextBox_Invoice_Date1_1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Invoice_Date1_1_Degree_courses.Text);
                
                TextBox_Amount1_1_Degree_courses.Text = rowUser["Amount1_1_Degree_courses"].ToString().Trim();
                TextBox_Note1_1_Degree_courses.Text = rowUser["Note1_1_Degree_courses"].ToString().Trim();

                TextBox_Received_Date2_1_Degree_courses.Text = rowUser["Received_Date2_1_Degree_courses"].ToString().Trim();
                TextBox_Received_Date2_1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Received_Date2_1_Degree_courses.Text);
                
                TextBox_Invoice_No2_1_Degree_courses.Text = rowUser["Invoice_No2_1_Degree_courses"].ToString().Trim();
                TextBox_Invoice_Date2_1_Degree_courses.Text = rowUser["Invoice_Date2_1_Degree_courses"].ToString().Trim();
                TextBox_Invoice_Date2_1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Invoice_Date2_1_Degree_courses.Text);
                
                TextBox_Amount2_1_Degree_courses.Text = rowUser["Amount2_1_Degree_courses"].ToString().Trim();
                TextBox_Note2_1_Degree_courses.Text = rowUser["Note2_1_Degree_courses"].ToString().Trim();

                
                TextBox_Received_Date3_1_Degree_courses.Text = rowUser["Received_Date3_1_Degree_courses"].ToString().Trim();
                TextBox_Received_Date3_1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Received_Date3_1_Degree_courses.Text);
                TextBox_Invoice_No3_1_Degree_courses.Text = rowUser["Invoice_No3_1_Degree_courses"].ToString().Trim();
                TextBox_Invoice_Date3_1_Degree_courses.Text = rowUser["Invoice_Date3_1_Degree_courses"].ToString().Trim();
                TextBox_Invoice_Date3_1_Degree_courses.Text = Common_SXD.TimeToYMD(TextBox_Invoice_Date3_1_Degree_courses.Text);
                TextBox_Amount3_1_Degree_courses.Text = rowUser["Amount3_1_Degree_courses"].ToString().Trim();
                TextBox_Note3_1_Degree_courses.Text = rowUser["Note3_1_Degree_courses"].ToString().Trim();
                
            }

            
        }

        private enum Func
        {
            EditRegisterData,
            ReadOnly,
            AddedRegisterData
        }

        /// <summary>
        /// 读取功能标识
        /// </summary>
        private Func Get_Function(string strFunction)
        {
            Regex NotEditFirstPayment = new Regex("([a-zA-Z_]{1,}):([0-9]{1,})");
            Regex NewOneFirstPayment = new Regex("(NewOne)");
            Regex EditFirstPayment = new Regex("([0-9]{1,})");
            string[] temp;

            if (NotEditFirstPayment.IsMatch(strFunction))
            {
                temp = NotEditFirstPayment.Split(strFunction);
                if (temp[1] == "ReadOnly")
                {// 只读方式读取合同数据
                    return Func.ReadOnly;
                }
                else if (temp[1] == "AddedRegisterData")
                {// 
                    return Func.AddedRegisterData;
                }
                else if (temp[1] == "EditRegisterData")
                {
                    return Func.EditRegisterData;
                }
             }

            return Func.ReadOnly;
        }


        /////////////////////////////
        /// <summary>
        /// 更新合同数据库佣金数据记录（不是新数据）。
        /// </summary>
        /// <remarks>
        /// 只有修改数据的控件有效（enable）时，该数据才能被更新。
        /// </remarks>
        public void Update_CommissionEdit()
        {
            ////
            if (CheckBox_Add_Course1_Degree_courses.Checked)
            {
                Response.Write("<li>现在是添加课程状态，不能修改注册信息！</li>");
                return;
            }
            ////
            if (!CheckBox_Commission_1_Degree_courses.Checked)
            {
                Response.Write("<li>不能修改佣金数据！</li>");
                return;
            }
            
            //合同信息写入数据库
            string sSql = "Update Contract Set";
          
            //////////////////////
            /// 佣金 commission 相关数据的更新
            sSql = sSql_Add_DateTime(TextBox_Received_Date1_1_Degree_courses, "Received_Date1_1_Degree_courses", sSql);
            sSql = sSql_Add_DateTime(TextBox_Received_Date2_1_Degree_courses, "Received_Date2_1_Degree_courses", sSql);
            sSql = sSql_Add_DateTime(TextBox_Received_Date3_1_Degree_courses, "Received_Date3_1_Degree_courses", sSql);
            sSql = sSql_Add_Number(TextBox_Rate_1_Degree_courses, "Rate_1_Degree_courses", sSql);
            
            sSql = sSql_Add_TextBox(TextBox_Invoice_No1_1_Degree_courses, "Invoice_No1_1_Degree_courses", sSql);
            sSql = sSql_Add_DateTime(TextBox_Invoice_Date1_1_Degree_courses, "Invoice_Date1_1_Degree_courses", sSql);
            sSql = sSql_Add_Number(TextBox_Amount1_1_Degree_courses, "Amount1_1_Degree_courses", sSql);
            sSql = sSql_Add_TextBox(TextBox_Note1_1_Degree_courses, "Note1_1_Degree_courses", sSql);
            
            sSql = sSql_Add_TextBox(TextBox_Invoice_No2_1_Degree_courses, "Invoice_No2_1_Degree_courses", sSql);
            sSql = sSql_Add_DateTime(TextBox_Invoice_Date2_1_Degree_courses, "Invoice_Date2_1_Degree_courses", sSql);
            sSql = sSql_Add_Number(TextBox_Amount2_1_Degree_courses, "Amount2_1_Degree_courses", sSql);
            sSql = sSql_Add_TextBox(TextBox_Note2_1_Degree_courses, "Note2_1_Degree_courses", sSql);
            

            sSql = sSql_Add_TextBox(TextBox_Invoice_No3_1_Degree_courses, "Invoice_No3_1_Degree_courses", sSql);
            sSql = sSql_Add_DateTime(TextBox_Invoice_Date3_1_Degree_courses, "Invoice_Date3_1_Degree_courses", sSql);
            sSql = sSql_Add_Number(TextBox_Amount3_1_Degree_courses, "Amount3_1_Degree_courses", sSql);
            sSql = sSql_Add_TextBox(TextBox_Note3_1_Degree_courses, "Note3_1_Degree_courses", sSql);
            
            /// 最后一个 set 组
            sSql += " Notes_Co_accommodation = '" + TextBox_Notes_Co_accommodation.Text.Trim() + "' ";

            ///////////////////////////////////////



            sSql += " where Series_No = " + "'" + Label_Msg.Text.Trim() + "'";
#if MSSql
            Common_SXD.MSSql_ExecuteNonQuery(sSql, "", "打开数据库出错！", Response);
#elif MySql
            Common_SXD.MySql_ExecuteNonQuery(sSql, "", "打开数据库出错！", Response);
#endif
        }// end of Update_CommissionEdit()

        /////////////////////////////
        /// <summary>
        /// 更新合同数据库注册数据记录（不是新数据）。
        /// </summary>
        /// <remarks>
        /// 只有修改数据的控件有效（enable）时，该数据才能被更新。
        /// </remarks>
        public void Update_RegisterEdit()
        {
            ////
            if (CheckBox_Add_Course1_Degree_courses.Checked)
            {
                Response.Write("<li>现在是添加课程状态，不能修改注册信息！</li>");
                return;
            }
            //合同信息写入数据库
            string sSql = "Update Contract Set";

            ////////////////////
            ///学生基本信息
            /*if (TextBox_UKEAS_ID.Enabled)
                sSql += " UKEAS_ID = '" + TextBox_UKEAS_ID.Text.Trim() + "', ";

            if (Drop_Gender_Student.Enabled)
                sSql += " Gender_Student = '" + Drop_Gender_Student.SelectedItem.Text.Trim() + "', ";
            */
            sSql = sSql_Add_TextBox(TextBox_UKEAS_ID, "UKEAS_ID", sSql);
            sSql = sSql_Add_DropDownList(Drop_Gender_Student, "Gender_Student", sSql);
            sSql = sSql_Add_DateTime(TextBox_Date_Birth, "Date_Birth", sSql );

            sSql = sSql_Add_DropDownList(Drop_YearMonth_Start, TextBox_YearMonth_Start, "YearMonth_Start", sSql);
            
            ////////////////////
            ///长期课程院校1
            ///if (Drop_Course1_Degree_courses.Enabled)/// 下拉选项有效，用TextBox更新数据库字段
            ///    sSql += " Course1_Degree_courses = '" + TextBox_Course1_Degree_courses.Text.Trim() + "', ";
            sSql = sSql_Add_DropDownList(Drop_Course1_Degree_courses, "Course1_Degree_courses", sSql);
            
            //if (Drop_College1_Degree_courses.Enabled)
            //    sSql += " College1_Degree_courses = '" + Drop_College1_Degree_courses.SelectedItem.Text.Trim() + "', ";
            sSql = sSql_Add_DropDownList(Drop_College1_Degree_courses,  "College1_Degree_courses", sSql);
            
            if (TextBox_Start1_Degree_courses.Enabled )
                if (TextBox_Finish1_Degree_courses.Text.Trim() != "")
                    sSql += " Start1_Degree_courses = '" + TextBox_Start1_Degree_courses.Text.Trim() + "', ";
                else
                    sSql += " Start1_Degree_courses = '1900-1-1', ";

            if (TextBox_Finish1_Degree_courses.Enabled )
                if( TextBox_Finish1_Degree_courses.Text.Trim() != "" )
                   sSql += " Finish1_Degree_courses = '" + TextBox_Finish1_Degree_courses.Text.Trim() + "', ";
                else
                    sSql += " Finish1_Degree_courses = '1900-1-1', ";

            if (Drop_Level1_Degree_courses.Enabled)
                sSql += " Level1_Degree_courses = '" + Drop_Level1_Degree_courses.SelectedItem.Text.Trim() + "', ";

            if (Drop_Type1_Degree_courses.Enabled)
                sSql += " Type1_Degree_courses = '" + Drop_Type1_Degree_courses.SelectedItem.Text.Trim() + "', ";

            ///if (TextBox_Tuition1_Degree_courses.Enabled)
            ///    if (TextBox_Tuition1_Degree_courses.Text.Trim() != "")
            ///        sSql += " Tuition1_Degree_courses = " + TextBox_Tuition1_Degree_courses.Text.Trim() + ", ";
            ///    else
            ///        sSql += " Tuition1_Degree_courses = 0 , ";

            sSql = sSql_Add_Number(TextBox_Tuition1_Degree_courses, "Tuition1_Degree_courses", sSql);

            if (TextBox_Notes1_Degree_courses.Enabled)
                sSql += " Notes1_Degree_courses = '" + TextBox_Notes1_Degree_courses.Text.Trim() + "', ";
            
            string temp;
            if (CheckBox_Helicopter1_Degree_courses.Enabled)
            {
                if (CheckBox_Helicopter1_Degree_courses.Checked == true)
                    temp = "1";
                else
                    temp = "0";
                sSql += " Helicopter1_Degree_courses = " + temp + ", ";
            }

            if (TextBox_Ref_No1_Degree_courses.Enabled)
                sSql += " Ref_No1_Degree_courses = '" + TextBox_Ref_No1_Degree_courses.Text.Trim() + "', ";

            ////////////////////
            ///长期课程院校2     
            ///if (TextBox_Course2_Degree_courses.Enabled)
            ///    sSql += " Course2_Degree_courses = '" + TextBox_Course2_Degree_courses.Text.Trim() + "', ";
            sSql = sSql_Add_TextBox(TextBox_Course2_Degree_courses, "Course2_Degree_courses", sSql);
            
            ///if (Drop_College2_Degree_courses.Enabled)
            ///    sSql += " College2_Degree_courses = '" + Drop_College2_Degree_courses.SelectedItem.Text.Trim() + "', ";
            sSql = sSql_Add_DropDownList(Drop_College2_Degree_courses, "College2_Degree_courses", sSql);

            if (TextBox_Start2_Degree_courses.Enabled)
                if (TextBox_Start2_Degree_courses.Text.Trim() != "")
                    sSql += " Start2_Degree_courses = '" + TextBox_Start2_Degree_courses.Text.Trim() + "', ";
                else
                    sSql += " Start2_Degree_courses = '1900-1-1', ";

            ///if (TextBox_Finish2_Degree_courses.Enabled)
            ///    if (TextBox_Finish2_Degree_courses.Text.Trim() != "")
            ///        sSql += " Finish2_Degree_courses = '" + TextBox_Finish2_Degree_courses.Text.Trim() + "', ";
            ///    else
            ///        sSql += " Finish2_Degree_courses = '1900-1-1', ";

            sSql = sSql_Add_DateTime(TextBox_Finish2_Degree_courses, "Finish2_Degree_courses", sSql);

            sSql = sSql_Add_DropDownList(Drop_Level2_Degree_courses,  "Level2_Degree_courses", sSql);
            sSql = sSql_Add_DropDownList(Drop_Type2_Degree_courses,  "Type2_Degree_courses", sSql);
            
            if (TextBox_Tuition2_Degree_courses.Enabled)
                if (TextBox_Tuition2_Degree_courses.Text.Trim() != "")
                    sSql += " Tuition2_Degree_courses = " + TextBox_Tuition2_Degree_courses.Text.Trim() + ", ";
                else
                    sSql += " Tuition2_Degree_courses = 0 , ";

            if (TextBox_Notes2_Degree_courses.Enabled)
                sSql += " Notes2_Degree_courses = '" + TextBox_Notes2_Degree_courses.Text.Trim() + "', ";
            /*
            if (CheckBox_Helicopter2_Degree_courses.Enabled)
            {
                if (CheckBox_Helicopter2_Degree_courses.Checked == true)
                    temp = "1";
                else
                    temp = "0";
                sSql += " Helicopter2_Degree_courses = " + temp + ", ";
            }
            */

            sSql = sSql_Add_Checkd(CheckBox_Helicopter2_Degree_courses, "Helicopter2_Degree_courses", sSql);

            if (TextBox_Ref_No2_Degree_courses.Enabled)
                sSql += " Ref_No2_Degree_courses = '" + TextBox_Ref_No2_Degree_courses.Text.Trim() + "', ";

            //////////////////
            ///学前语言学校
            ///if (TextBox_Course_Pre_sessional.Enabled)
            ///    sSql += " Course_Pre_sessional = '" + TextBox_Course_Pre_sessional.Text.Trim() + "', ";

            ///if (Drop_College_Pre_sessional.Enabled)
            ///    sSql += " College_Pre_sessional = '" + Drop_College_Pre_sessional.SelectedItem.Text.Trim() + "', ";

            sSql = sSql_Add_TextBox(TextBox_Course_Pre_sessional, "Course_Pre_sessional", sSql);
            sSql = sSql_Add_DropDownList(Drop_College_Pre_sessional, "College_Pre_sessional", sSql);

            if (TextBox_Wks_Pre_sessional.Enabled)
                if (TextBox_Wks_Pre_sessional.Text.Trim() != "")
                    sSql += " Wks_Pre_sessional = " + TextBox_Wks_Pre_sessional.Text.Trim() + ", ";
                else
                    sSql += " Wks_Pre_sessional = 0 , ";
            
            if (TextBox_Start_Pre_sessional.Enabled)
                if (TextBox_Start_Pre_sessional.Text.Trim() != "")
                    sSql += " Start_Pre_sessional = '" + TextBox_Start_Pre_sessional.Text.Trim() + "', ";
                else
                    sSql += " Start_Pre_sessional = '1900-1-1', ";

            if (TextBox_Finish_Pre_sessional.Enabled)
                if (TextBox_Finish_Pre_sessional.Text.Trim() != "")
                    sSql += " Finish_Pre_sessional = '" + TextBox_Finish_Pre_sessional.Text.Trim() + "', ";
                else
                    sSql += " Finish_Pre_sessional = '1900-1-1', ";

            if (Drop_Type_Pre_sessional.Enabled)
                sSql += " Type_Pre_sessional = '" + Drop_Type_Pre_sessional.SelectedItem.Text.Trim() + "', ";

            if (TextBox_Fee_Pre_sessional.Enabled)
                if (TextBox_Fee_Pre_sessional.Text.Trim() != "")
                    sSql += " Fee_Pre_sessional = " + TextBox_Fee_Pre_sessional.Text.Trim() + ", ";
                else
                    sSql += " Fee_Pre_sessional = 0 , ";

            if (TextBox_Notes_Pre_sessional.Enabled)
                sSql += " Notes_Pre_sessional = '" + TextBox_Notes_Pre_sessional.Text.Trim() + "', ";

            if (TextBox_Ref_No_Pre_sessional.Enabled)
                sSql += " Ref_No_Pre_sessional = '" + TextBox_Ref_No_Pre_sessional.Text.Trim() + "', ";

            /////////////////////
            /// INTO保险金额
            if (TextBox_Fee_INTO_Insurance.Enabled)
                if (TextBox_Fee_INTO_Insurance.Text.Trim() != "")
                    sSql += " Fee_INTO_Insurance = " + TextBox_Fee_INTO_Insurance.Text.Trim() + ", ";
                else
                    sSql += " Fee_INTO_Insurance = 0 , ";

            ////////////////////
            /// 语言院校
            /// 
            ///if (TextBox_Course_Language_School.Enabled)
            ///    sSql += " Course_Language_School = '" + TextBox_Course_Language_School.Text.Trim() + "', ";

            ///if (Drop_College_Language_School.Enabled)
            ///    sSql += " College_Language_School = '" + Drop_College_Language_School.SelectedItem.Text.Trim() + "', ";

            sSql = sSql_Add_TextBox(TextBox_Course_Language_School, "Course_Language_School", sSql);
            sSql = sSql_Add_DropDownList(Drop_College_Language_School, "College_Language_School", sSql);

            if (TextBox_Wks_Language_School.Enabled)
                if (TextBox_Wks_Language_School.Text.Trim() != "")
                    sSql += " Wks_Language_School = " + TextBox_Wks_Language_School.Text.Trim() + ", ";
                else
                    sSql += " Wks_Language_School = 0 , ";

            if (TextBox_Start_Language_School.Enabled)
                if (TextBox_Start_Language_School.Text.Trim() != "")
                    sSql += " Start_Language_School = '" + TextBox_Start_Language_School.Text.Trim() + "', ";
                else
                    sSql += " Start_Language_School = '1900-1-1', ";

            if (TextBox_Finish_Language_School.Enabled)
                if (TextBox_Finish_Language_School.Text.Trim() != "")
                    sSql += " Finish_Language_School = '" + TextBox_Finish_Language_School.Text.Trim() + "', ";
                else
                    sSql += " Finish_Language_School = '1900-1-1', ";

            if (TextBox_Fee_Language_School.Enabled)
                if (TextBox_Fee_Language_School.Text.Trim() != "")
                    sSql += " Fee_Language_School = " + TextBox_Fee_Language_School.Text.Trim() + ", ";
                else
                    sSql += " Fee_Language_School = 0 , ";

            ///if (TextBox_Notes_Language_School.Enabled)
            ///    sSql += " Notes_Language_School = '" + TextBox_Notes_Language_School.Text.Trim() + "', ";

            //////////////////////
            /// 校外住宿
            ///if (TextBox_Residence_Name_Co_accommodation.Enabled)
            ///    sSql += " Residence_Name_Co_accommodation = '" + TextBox_Residence_Name_Co_accommodation.Text.Trim() + "', ";

            ///if (Drop_Private_Co_accommodation_name.Enabled)
            ///    sSql += " Private_Co_accommodation_name = '" + Drop_Private_Co_accommodation_name.SelectedItem.Text.Trim() + "', ";
            sSql = sSql_Add_TextBox(TextBox_Notes_Language_School, "Notes_Language_School", sSql);
            sSql = sSql_Add_TextBox(TextBox_Residence_Name_Co_accommodation, "Residence_Name_Co_accommodation", sSql);
            sSql = sSql_Add_DropDownList(Drop_Private_Co_accommodation_name, "Private_Co_accommodation_name", sSql);

            if (TextBox_Wks_Co_accommodation.Enabled)
                if (TextBox_Wks_Co_accommodation.Text.Trim() != "")
                    sSql += " Wks_Co_accommodation = " + TextBox_Wks_Co_accommodation.Text.Trim() + ", ";
                else
                    sSql += " Wks_Co_accommodation = 0 , ";

            if (TextBox_Start_Co_accommodation.Enabled)
                if (TextBox_Start_Co_accommodation.Text.Trim() != "")
                    sSql += " Start_Co_accommodation = '" + TextBox_Start_Co_accommodation.Text.Trim() + "', ";
                else
                    sSql += " Start_Co_accommodation = '1900-1-1', ";

            if (TextBox_Finish_Co_accommodation.Enabled)
                if (TextBox_Finish_Co_accommodation.Text.Trim() != "")
                    sSql += " Finish_Co_accommodation = '" + TextBox_Finish_Co_accommodation.Text.Trim() + "', ";
                else
                    sSql += " Finish_Co_accommodation = '1900-1-1', ";

            if (TextBox_Ref_No_Co_accommodation.Enabled) 
            sSql += " Ref_No_Co_accommodation = '" + TextBox_Ref_No_Co_accommodation.Text.Trim() + "', ";

            if (TextBox_Fee_Co_accommodation.Enabled)
                if (TextBox_Fee_Co_accommodation.Text.Trim() != "")
                    sSql += " Fee_Co_accommodation = " + TextBox_Fee_Co_accommodation.Text.Trim() + ", ";
                else
                    sSql += " Fee_Co_accommodation = 0 , ";

            ///if (TextBox_Notes_Co_accommodation.Enabled) 最后一个 set 组
                sSql += " Notes_Co_accommodation = '" + TextBox_Notes_Co_accommodation.Text.Trim() + "' ";

            ///////////////////////////////////////


           
            sSql += " where Series_No = " + "'" + Label_Msg.Text.Trim() + "'";
#if MSSql
            Common_SXD.MSSql_ExecuteNonQuery(sSql, "", "打开数据库出错！", Response);
#elif MySql
            Common_SXD.MySql_ExecuteNonQuery(sSql, "", "打开数据库出错！", Response);
#endif
        }// end of Update_Contract()

        /// <summary>
        /// 管理员、总部会计在佣金管理上的权限控制。
        /// </summary>
        private void Admin_Accountant_Controls()
        {
            bool bIs_Admin = Convert.ToBoolean(Session["Is_Admin"]);
            bool bIs_Accountant = Convert.ToBoolean(Session["Is_Accountant"]);

            /// 只有管理员和总部会计，可以存取佣金数据
            if (bIs_Admin || bIs_Accountant)
            {
                CheckBox_Commission_1_Degree_courses.Enabled = true;
            }
            else
            {
                CheckBox_Commission_1_Degree_courses.Enabled = false;
                CheckBox_Commission_1_Degree_courses.Checked = false;
            }

        }

        /// <summary>
        /// 佣金相关的页面交互控制。
        /// </summary>
        private void Commission_Controls()
        {
            if (!CheckBox_Commission_1_Degree_courses.Checked)
            {/// 不显示佣金数据

                TextBox_Rate_1_Degree_courses.Visible = false;
                TextBox_Received_Date1_1_Degree_courses.Visible = false;
                TextBox_Received_Date2_1_Degree_courses.Visible = false;
                TextBox_Received_Date3_1_Degree_courses.Visible = false;
                TextBox_Rate_1_Degree_courses.Enabled = false;
                Label_Rate_1_Degree_courses.Text = "";
                TextBox_Received_Date1_1_Degree_courses.Enabled = false;
                Label_Received_Date1_1_Degree_courses.Text = "";
                TextBox_Received_Date2_1_Degree_courses.Enabled = false;
                Label_Received_Date2_1_Degree_courses.Text = "";
                TextBox_Received_Date3_1_Degree_courses.Enabled = false;
                Label_Received_Date3_1_Degree_courses.Text = "";
                
                TextBox_Invoice_No1_1_Degree_courses.Visible = false;
                TextBox_Invoice_No2_1_Degree_courses.Visible = false;
                TextBox_Invoice_No3_1_Degree_courses.Visible = false;
                TextBox_Invoice_No1_1_Degree_courses.Enabled = false;
                Label_Invoice_No1_1_Degree_courses.Text = "";
                TextBox_Invoice_No2_1_Degree_courses.Enabled = false;
                Label_Invoice_No2_1_Degree_courses.Text = "";
                TextBox_Invoice_No3_1_Degree_courses.Enabled = false;
                Label_Invoice_No3_1_Degree_courses.Text = "";

                TextBox_Invoice_Date1_1_Degree_courses.Visible = false;
                TextBox_Invoice_Date2_1_Degree_courses.Visible = false;
                TextBox_Invoice_Date3_1_Degree_courses.Visible = false;
                TextBox_Invoice_Date1_1_Degree_courses.Enabled = false;
                Label_Invoice_Date1_1_Degree_courses.Text = "";
                TextBox_Invoice_Date2_1_Degree_courses.Enabled = false;
                Label_Invoice_Date2_1_Degree_courses.Text = "";
                TextBox_Invoice_Date3_1_Degree_courses.Enabled = false;
                Label_Invoice_Date3_1_Degree_courses.Text = "";
                
                TextBox_Amount1_1_Degree_courses.Visible = false;
                TextBox_Amount2_1_Degree_courses.Visible = false;
                TextBox_Amount3_1_Degree_courses.Visible = false;
                TextBox_Amount1_1_Degree_courses.Enabled = false;
                Label_Amount1_1_Degree_courses.Text = "";
                TextBox_Amount2_1_Degree_courses.Enabled = false;
                Label_Amount2_1_Degree_courses.Text = "";
                TextBox_Amount3_1_Degree_courses.Enabled = false;
                Label_Amount3_1_Degree_courses.Text = "";
                
                TextBox_Note1_1_Degree_courses.Visible = false;
                TextBox_Note2_1_Degree_courses.Visible = false;
                TextBox_Note3_1_Degree_courses.Visible = false;
                TextBox_Note1_1_Degree_courses.Enabled = false;
                Label_Note1_1_Degree_courses.Text = "";
                TextBox_Note2_1_Degree_courses.Enabled = false;
                Label_Note2_1_Degree_courses.Text = "";
                TextBox_Note3_1_Degree_courses.Enabled = false;
                Label_Note3_1_Degree_courses.Text = "";
                
            }
            else
            { /// 修改佣金数据
                TextBox_Rate_1_Degree_courses.Visible = true;

                TextBox_Received_Date1_1_Degree_courses.Visible = true;
                TextBox_Received_Date2_1_Degree_courses.Visible = true;
                TextBox_Received_Date3_1_Degree_courses.Visible = true;
                TextBox_Rate_1_Degree_courses.Enabled = true;
                Label_Rate_1_Degree_courses.Text = "佣金比例";
                TextBox_Received_Date1_1_Degree_courses.Enabled = true;
                Label_Received_Date1_1_Degree_courses.Text = "(课程1佣金)收到日期1";
                TextBox_Received_Date2_1_Degree_courses.Enabled = true;
                Label_Received_Date2_1_Degree_courses.Text = "(课程1佣金)收到日期2";
                TextBox_Received_Date3_1_Degree_courses.Enabled = true;
                Label_Received_Date3_1_Degree_courses.Text = "(课程1佣金)收到日期3";

                TextBox_Invoice_No1_1_Degree_courses.Visible = true;
                TextBox_Invoice_No2_1_Degree_courses.Visible = true;
                TextBox_Invoice_No3_1_Degree_courses.Visible = true;
                TextBox_Invoice_No1_1_Degree_courses.Enabled = true;
                Label_Invoice_No1_1_Degree_courses.Text = "(课程1佣金)发票编号1";
                TextBox_Invoice_No2_1_Degree_courses.Enabled = true;
                Label_Invoice_No2_1_Degree_courses.Text = "(课程1佣金)发票编号2";
                TextBox_Invoice_No3_1_Degree_courses.Enabled = true;
                Label_Invoice_No3_1_Degree_courses.Text = "(课程1佣金)发票编号3";

                TextBox_Invoice_Date1_1_Degree_courses.Visible = true;
                TextBox_Invoice_Date2_1_Degree_courses.Visible = true;
                TextBox_Invoice_Date3_1_Degree_courses.Visible = true;
                TextBox_Invoice_Date1_1_Degree_courses.Enabled = true;
                Label_Invoice_Date1_1_Degree_courses.Text = "发票日期1";
                TextBox_Invoice_Date2_1_Degree_courses.Enabled = true;
                Label_Invoice_Date2_1_Degree_courses.Text = "发票日期2";
                TextBox_Invoice_Date3_1_Degree_courses.Enabled = true;
                Label_Invoice_Date3_1_Degree_courses.Text = "发票日期3";

                TextBox_Amount1_1_Degree_courses.Visible = true;
                TextBox_Amount2_1_Degree_courses.Visible = true;
                TextBox_Amount3_1_Degree_courses.Visible = true;
                TextBox_Amount1_1_Degree_courses.Enabled = true;
                Label_Amount1_1_Degree_courses.Text = "佣金1";
                TextBox_Amount2_1_Degree_courses.Enabled = true;
                Label_Amount2_1_Degree_courses.Text = "佣金2";
                TextBox_Amount3_1_Degree_courses.Enabled = true;
                Label_Amount3_1_Degree_courses.Text = "佣金3";

                TextBox_Note1_1_Degree_courses.Visible = true;
                TextBox_Note2_1_Degree_courses.Visible = true;
                TextBox_Note3_1_Degree_courses.Visible = true;
                TextBox_Note1_1_Degree_courses.Enabled = true;
                Label_Note1_1_Degree_courses.Text = "备注1";
                TextBox_Note2_1_Degree_courses.Enabled = true;
                Label_Note2_1_Degree_courses.Text = "备注2";
                TextBox_Note3_1_Degree_courses.Enabled = true;
                Label_Note3_1_Degree_courses.Text = "备注3";

            }
            

        }


        /// <summary>
        ///  关闭部分的页面交互控制。
        /// </summary>
        private void false_Enable_Some_Controls()
        {
            TextBox_Office.Enabled = false;
            TextBox_Student_Name.Enabled = false;
            TextBox_Counsellor.Enabled = false;
            TextBox_Pinyi.Enabled = false;
            TextBox_Course1_Degree_courses.Enabled = false;
            TextBox_YearMonth_Start.Enabled = false;
            Button_Course1_Degree_courses.Visible = false;

            ///先判断添加该校课程
            if (CheckBox_Add_Course1_Degree_courses.Checked)
            {
                Drop_Course1_Degree_courses.Enabled = false;
                Drop_Course1_Degree_courses.Visible = false;

                Drop_College1_Degree_courses.Enabled = false;
                TextBox_Course1_Degree_courses.Enabled = true;
                
                Button_Course1_Degree_courses.Visible = true;
                Button_Course1_Degree_courses.Enabled = true;
                CheckBox_Course1_Degree_courses.Checked = false;
                CheckBox_Course1_Degree_courses.Enabled = false;

            }
            else if (CheckBox_Course1_Degree_courses.Checked)
            {
                Drop_Course1_Degree_courses.Enabled = true;
                Drop_Course1_Degree_courses.Visible = true;

                Drop_College1_Degree_courses.Enabled = false;
                CheckBox_Course1_Degree_courses.Enabled = true;
            }
            else
            {
                Drop_Course1_Degree_courses.Enabled = false;
                Drop_Course1_Degree_courses.Visible = true;

                Drop_College1_Degree_courses.Enabled = true;
                CheckBox_Course1_Degree_courses.Enabled = true;
                
            }

        
        }

        protected void Bt_OK_Click(object sender, EventArgs e)
        {
            switch (Get_Function(Session["Flag"].ToString().Trim()))
            {
                case Func.AddedRegisterData: 	// 添加一个新的记录
                    ////////////////////////
                    ///处理已经存在的学生名
                    ////////////////////////
                    string sSql_Search = "";
                    ///已经注册的学生
                    sSql_Search += " ( ( College1_Degree_courses not like '%无%' and  College1_Degree_courses is not null and College1_Degree_courses not like '' ) or ";
                    sSql_Search += " ( College2_Degree_courses not like '%无%' and  College2_Degree_courses is not null and College2_Degree_courses not like '' ) or ";
                    sSql_Search += " ( College_Pre_sessional not like '%无%' and  College_Pre_sessional is not null and College_Pre_sessional not like '' ) or ";
                    sSql_Search += " ( College_Language_School not like '%无%' and  College_Language_School is not null and College_Language_School not like '' ) or ";
                    sSql_Search += " ( Private_Co_accommodation_name not like '%无%' and  Private_Co_accommodation_name is not null and Private_Co_accommodation_name not like '' ) ";
                    sSql_Search += ") and ";
                    sSql_Search += "YearMonth_Start like '" + TextBox_YearMonth_Start.Text.Trim() + "' and ";
                    sSql_Search += "Counsellor like '" + TextBox_Counsellor.Text.Trim() + "' and ";
                    sSql_Search += "Office like '" + TextBox_Office.Text.Trim() + "' and Student_Name like '" + TextBox_Student_Name.Text.Trim() + "'";
#if MSSql
                    string sCounter = Common_SXD.CHAR_MSSQL_PLUS1("select count(Series_No) from Contract ",
                       sSql_Search, Response);
#elif MySql
                    string sCounter = Common_SXD.CHAR_MySQL_PLUS1("select count(Series_No) from Contract ",
                       sSql_Search, Response);
#endif
                    if (!CheckBox_AllowedSameName.Checked)
                    {
                        if (Convert.ToInt16(sCounter) > 1)
                        {
                            Response.Write("<li>已经存在" + Convert.ToString((Convert.ToInt16(sCounter) - 1)).Trim() + "个‘" + TextBox_Student_Name.Text.Trim() + "’的合同！无法添加！</li>");
                            return;
                        }
                        else
                            Response.Clear();
                    }
                    else
                        Response.Clear();

                    Update_RegisterEdit();
                    Update_CommissionEdit();
                    ///???
                    Init_AddedRegisterData();
                    break;
                case Func.EditRegisterData :		// 修改一期付款
                    Update_RegisterEdit();
                    Update_CommissionEdit();
                    Init_EditRegisterData();
                    Init_EditCommissionData();
                break;
                case Func.ReadOnly:
                /*    if (!Is_SuperUser(false))//Session["Email"].ToString().Trim() != "jianwei_rong")
                        break;
                    else
                        Update_Contract();
                    Init_ReadOnly();
                    break;
                 **/
                default:
                    break;

            }

        }

        protected void Drop_YearMonth_Start_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_YearMonth_Start.Text = Drop_YearMonth_Start.SelectedItem.Text.ToString().Trim();
        
        }

        protected void Drop_Course1_Degree_courses_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_Course1_Degree_courses.Text = Drop_Course1_Degree_courses.SelectedItem.Text.ToString().Trim();
        
        }

        protected void Button_Course1_Degree_courses_Click(object sender, EventArgs e)
        {
            string temp = TextBox_Course1_Degree_courses.Text.Trim();
            if (temp == "无")
            {
                Response.Write("<li>不能添加‘无’！</li>");
                return;
            }
            string strSQL = "select count(*) from Courses_Schools  ";
            string strFilter = "Course like '" + Double_Single_Quotation(temp) + "' and School like '" + Double_Single_Quotation(Drop_College1_Degree_courses.SelectedItem.Text.Trim()) + "' ";  ///or ";
            ///strFilter += "Course like '无'";

            ///string temp;
            ///temp = "select * from Courses_Schools where Course like '无' or School like '" + Double_Single_Quotation(Drop_College1_Degree_courses.SelectedItem.Text.Trim()) + "' order by Course asc";
                
            ///如果课程重复，不添加
#if MySql
            string sCounter = Common_SXD.CHAR_MySQL_PLUS1(strSQL, strFilter, Response); ///院校1课程已经采用MySql数据库
#elif MSSql
            string sCounter = Common_SXD.CHAR_MSSQL_PLUS1(strSQL, strFilter, Response);
#endif
            if (Convert.ToInt16(sCounter) > 1)
            {
                Response.Write("<li>已经存在" + Convert.ToString((Convert.ToInt16(sCounter) - 1)).Trim() + "个相同的‘课程’无法添加！</li>");
                return;
            }

            strSQL = "insert into Courses_Schools  (School, Course) ";
            strSQL += "values('" + Double_Single_Quotation(Drop_College1_Degree_courses.SelectedItem.Text.Trim()) + "','" + Double_Single_Quotation(temp) +"')";

///#if MySql
            Common_SXD.MySql_ExecuteNonQuery(strSQL, "", "打开数据库出错！", Response); ///院校1课程已经采用MySql数据库
///#elif MSSql
///            Common_SXD.MSSql_ExecuteNonQuery(strSQL, "", "打开数据库出错！", Response);
///#endif

            CheckBox_Add_Course1_Degree_courses.Checked = false;
            Init_EditRegisterData();
            Init_EditCommissionData();
        }

        protected void Button_Refresh_Click(object sender, EventArgs e)
        {
            /// 从数据库中重新读取数据
            switch (Get_Function(Session["Flag"].ToString().Trim()))
            {
                case Func.ReadOnly:
                /*    if (!Is_SuperUser(false))//Session["Email"].ToString().Trim() != "jianwei_rong")
                        break;
                    else
                        Update_Contract();
                    Init_ReadOnly();
                    break;
                 **/
                case Func.EditRegisterData:		// 修改一期付款
                    ///Update_RegisterEdit();
                    Init_EditRegisterData();
                    Init_EditCommissionData();
                    break;
                
                default:
                    break;

            }
        }

         
    }
}